Loading resources in parallel

When users run your Kanzi application in an environment with a multi-core processor, Kanzi automatically uses multiple CPU cores to load the GPU resources in the .kzb files to RAM. Because the largest amount of data during the loading is processed by the GPU resources, parallel loading of resources significantly improves the loading time of your application.

GPU resources Kanzi loads in parallel include all types of textures, shaders, and meshes. To deploy these resources from RAM to GPU memory and to load prefab templates, Kanzi always uses the main thread. See Images and textures best practices, Shaders best practices, Meshes best practices.

In Kanzi you can load resource dictionaries of prefabs you use in your project before your Kanzi application shows them to users. For example, you can create a loading screen that your users see while Kanzi is loading the resource dictionaries of the rest of your application in the background. See Preloading resource dictionaries.

The number of loading threads differs between platforms. When you use the optimal number of loading threads for your platform you can expect a decrease in both the launch and full loading times of your Kanzi application.

Setting the number of cores used for loading

In the application code, either using the application framework configuration or the resource manager API, you can set the number of cores you want your application to use to load the GPU resources.

Note that when you set the number of cores, you can set the size of the memory manager. If you do not set the size of the memory manager, or set it to 0, and loading thread count is larger than 0, Kanzi automatically uses half of the main memory pool for the resource loading.

To set the number of cores your application uses for loading the resources, in the C++ application in the onConfigure() function:

// Set loadingThreadCount to the number of cores in the processor
// of your target device.
// For example, to use all four cores of a four-core processor,
// set the value to 3, to use only two cores, set the value to 1.
configuration.loadingThreadCount = 3;

// Set the size of the memory manager between half and full amount allocated
// for the memory pool of your application.
// For example, if you allocated 200 MB for the memory pool, set
// the size of the memory manager between 100 and 200 MB.
configuration.loadingThreadsMemoryManagerSize = 100 * 1024 * 1024;

You can set the loading preferences for your application in the C++ application in the onConfigure() function or in the application.cfg. See Loading preferences.

Disabling parallel loading

To disable the parallel loading of resources, set loadingThreadCount to 0. When you disable the parallel loading, Kanzi uses only the main thread to load the resources. When you disable the parallel loading, Kanzi does not allocate the memory manager.

configuration.loadingThreadCount = 0;

See Loading preferences.

See also

Images and textures best practices

Meshes best practices

Shaders best practices

Resource management

Preloading resource dictionaries

Reference for application configuration